<template>
	<view class="content">
		<heade title="高级查询" cross bg_color="bg_fff"></heade>
		<view class="" style="margin-top: 4rpx;">
			<view class="d-flex p-t12 p-b12 p-l15 align-center bg_fff">
				<view class="f-s14 co_333 " style="width: 150rpx;">单据日期</view>
				<view class="flex1 d-flex align-center" @tap="show">
					<view class="f-s13" :class="time_1 == '开始时间'?'co_grey':'co_000'">{{time_1}}</view>
					<view class="m-l5 m-r5 co_999">~</view>
					<view class="f-s13" :class="time_2 == '结束时间'?'co_grey':'co_000'">{{time_2}}</view>
				</view>
				<!-- <xp-picker ref="picker" mode="ymd" placeholder=" " @confirm="confirm" /> -->
			</view>
			<view class="d-flex p-t12 p-b12 p-l15 align-center bg_fff m-t1">
				<view class="f-s14 co_333" style="width: 150rpx;">客户</view>
				<view class="f-s14 flex1" @tap="characterClick(1)" :class="partnerName.name==''?'co_grey':''">{{partnerName.name ==''?'请选择':partnerName.name}}</view>
			</view>
			<view class="d-flex p-t12 p-b12 p-l15 align-center bg_fff m-t1" @tap="characterClick(2)">
				<view class="f-s14 co_333" style="width: 150rpx;">结算客户</view>
				<view class="f-s14 flex1" :class="SettleCustomer.name ==''?'co_grey':''">{{SettleCustomer.name==''?'请选择':SettleCustomer.name}}</view>
			</view>
		<!-- 	<view class="d-flex p-t12 p-b12 p-l15 align-center bg_fff m-t1">
				<view class="f-s14 co_333" style="width: 150rpx;">存货编码</view>
				<view class="f-s14 flex1" :class="inventoryName==''?'co_grey':''">{{inventoryName==''?'请选择':inventoryName}}</view>
			</view> -->
		</view>
		<view class="b-liuhai" ><view style="height: 92rpx;"></view></view>
		<view style="position: fixed; bottom: 0;width: 100%;z-index: 9;" class="bg_fff" >
			<view class="b-liuhai d-flex align-center">
				<view class="f-w500 co_999 f-s17 text-center bg_fff" style="width: 50%; height: 92rpx;line-height: 92rpx;" @tap="resetClick">重置</view>
				<view class="f-w500 co_fff f-s17 text-center bg_4494EE	" style="width: 50%; height: 92rpx;line-height: 92rpx;" @tap="saveClick">确定</view>
			</view>
		</view>
		
		<wPopup :character="character" :slide="slide" @wSlide="slide = false" @wClose="disposition">
			<view class="bg_fff ">
				<view class="d-flex align-center justify-content-space-between p-t10 p-b15 p-l15 p-r15">
					<view class=" f-s14" @tap="changeVisble">取消</view>
					<view class="co_64acff f-s14" @tap="changeVisble(2)">清空</view>
				</view>
				<view class="p-l15 p-r15 p-b8" style="border-bottom: 2rpx solid #f3f3f3;">
					<view class="sousuo border-r12 d-flex align-center" style="width: 100%;">
						<view class="iconfont icon-sousuo f-s14 m-l10"></view>
						<input type="text" @blur="getData" v-model="Name" class="f-s14 m-l10 flex1" placeholder="搜索客户名称">
					</view>
				</view>
				<view class="" style="height: 400rpx;overflow-y: auto;">
					<view v-for="item in nameList" @tap="nameSelect(item)" class="jehuClass p-l15 p-r15 p-t10 p-b10" style="border-bottom: 2rpx solid #f3f3f3;">
						<view class="f-s14">{{item.name}}</view>
					</view>
				</view>
			</view>
		</wPopup>
		<wly-datetime-picker type="daterange" ref="wlyDatetime" @change="confirm" :isIcons="false"  />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				slide:false,
				character:false,
				count:false,
				partnerName:{name:'',code:''},
				SettleCustomer:{name:'',code:''},
				inventoryName:'',
				nameList:[],
				time_1:'开始时间',
				time_2:'结束时间',
				Name:''
			}
		},
		onLoad(e) {
			if(e.body) {
				let data = JSON.parse(e.body)
				if(data.partnerName) {
					this.partnerName = data.partnerName
				}
				if(data.SettleCustomer) {
					this.SettleCustomer = data.SettleCustomer
				}
				if(data.BeginDefault) {
					this.time_1 = data.BeginDefault
				}
				if(data.EndDefault) {
					this.time_2 = data.EndDefault
				}
			}
			this.getData()
		},
		onShow() {
		},
		methods: {
			// 获取客户数据
			getData() {
				this.$http.get('valet_order/partner_lists',{Name:this.Name}).then(res => {
					if(res.code == 1) {
						this.nameList = res.data
						this.Name = ''
					}
				})
			},
			// 获取客户数据
			getData() {
				this.$http.get('valet_order/partner_lists',{Name:this.Name}).then(res => {
					if(res.code == 1) {
						this.nameList = res.data
						this.Name = ''
					}
				})
			},
			// 弹框打开
			characterClick(i) {
				this.count = i
				this.character = true
			},
			saveClick() {
				var pages = getCurrentPages();
				var pages1 = pages[pages.length - 2]
				let itemList = [this.time_1,this.time_2]
				if(this.time_1 != '开始时间' && this.time_2 != '结束时间') {
					pages1.$vm.timeData = itemList
				}else{
					pages1.$vm.timeData = ['','']
				}
				if(this.partnerName.name != '') {
					pages1.$vm.partnerName = this.partnerName
				}else{
					pages1.$vm.partnerName = {name:'',code:''}
				}
				if(this.SettleCustomer.name != '') {
					pages1.$vm.SettleCustomer = this.SettleCustomer
				}else{
					pages1.$vm.SettleCustomer = {name:'',code:''}
				}
				uni.navigateBack()
			},
			changeVisble (i) {
				if(i == 2) {
					if(this.count == 1) {
						this.partnerName = {name:'',code:''}
					}else if (this.count == 2) {
						this.SettleCustomer = {name:'',code:''}
					}
				}
				if(this.character) {
					this.slide = true
					setTimeout(() =>{
						this.character = false
					},300)
				}else {
					this.slide = false
					this.character = true
				}
			},
			// 性格关闭
			disposition(){
				this.slide = false
				this.character = false
			},
			nameSelect(item) {
				if(this.count == 1) {
					this.partnerName = item
				}else if (this.count == 2) {
					this.SettleCustomer = item
				}
				this.changeVisble()
			},
			show() {
				this.$refs.wlyDatetime.show()
			},
			confirm(e) {
				if(this.time_1 == e[0] &&this.time_2 == e[1]) {
					this.time_1 = '开始时间';
					this.time_2 =  '结束时间'
				}else {
					this.time_1 = e[0];
					this.time_2 =  e[1]
				}
			},
			resetClick() {
				this.time_1 = '开始时间' 
				this.time_2 = '结束时间'
				this.partnerName = {name:'',code:''}
				this.SettleCustomer = {name:'',code:''}
			}
		}
	}
</script>

<style lang="scss">
	page{
		background: #ECECEC;
	}
	.jehuClass{
		
	}
</style>